package org.dt.common.base;

/**
 * @author Feng
 *
 */
public class Digitals {

	static char[] HEX = new char[] { '0', '1', '2', '3', '4', '5', '6', '7',
			'8', '9', 'a', 'b', 'c', 'd', 'e', 'f' };

	public static String byte2Hex(byte bytes[]) {
		return byte2Hex(bytes, 0, bytes.length);
	}

	static String byte2Hex(byte[] bytes, int begin, int len) {
		char[] buff = new char[len * 2];
		int end = begin + len;
		for (int i = begin, j = 0; i < end; ++i) {
			byte b = bytes[i];
			buff[j++] = HEX[((b >> 4) & 0x0f)];
			buff[j++] = HEX[(b & 0x0f)];
		}
		return new String(buff);
	}
}
